import 'package:cat_eye/config/string_config.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

/*
* @Package: method_channel
* @ClassName: method_channel_manager
* @Author: szj
* @CreateDate: 8/6/21 11:04 AM
* TODO flutter 和 android 混合开发通道封装
*/
class MethodChannelManager {
  static MethodChannelManager _manager;

  //第一步: 定义与Native进行交互的MethodChannel
  static const MethodChannel _methodChannel =
      MethodChannel(StringConfig.METHOD_CHANNEL_NAME);

  MethodChannelManager._();

  static MethodChannelManager getInstance() {
    if (_manager == null) {
      _manager = MethodChannelManager._();
    }
    return _manager;
  }

  /*
   * 用来测试通道是否成功
   * flutter 点击按钮 调用android的Toast
   */
  void showToast(String msg) async {
    /*
       *  toast 用来和android端标识
       *  msg 传入的具体消息
       */
    try {
      var androidData = await _methodChannel.invokeMethod("toast", msg);
      print("android返回回来的数据$androidData");
    } catch (e) {
      print("showToast$e");
    }
  }
}
